package com.ruoyi.business.config;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Configurable;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class AliBaBaIdentity {
//
//    public Map<String, Object> Identity(String name, String idCard) throws IOException {
//        String url = "http://alysmrz.market.alicloudapi.com";
//        String path = "/communication/personal/1882";
//        String method = "POST";
//        String appCode = "0234e4133bf143b081cadd69f5fb0b89";
//
//        Map<String, String> params = new HashMap<>();
//        params.put("idcard", idCard);
//        params.put("name",name);
//
//        OkHttpClient client = new OkHttpClient.Builder().build();
//        FormBody.Builder formbuilder = new FormBody.Builder();
//        Iterator<String> it = params.keySet().iterator();
//        while (it.hasNext()) {
//            String key = it.next();
//            formbuilder.add(key, params.get(key));
//        }
//        FormBody body = formbuilder.build();
//        Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode).post(body).build();
//        Response response = client.newCall(request).execute();
//        System.out.println("返回状态码" + response.code() + ",message:" + response.message());
//        Map<String,Object> resultMap=new HashMap<>();
//        resultMap.put("code",response.code());
//        resultMap.put("message",response.message());
//        return resultMap;
//    }

//    public static void main(String[] args) {
//        String host = "http://alysmrz.market.alicloudapi.com";
//        String path = "/communication/personal/1882";
//        String method = "POST";
//        String appcode = "0234e4133bf143b081cadd69f5fb0b89";
//        Map<String, String> headers = new HashMap<String, String>();
//        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
//        headers.put("Authorization", "APPCODE " + appcode);
//        //根据API的要求，定义相对应的Content-Type
//        headers.put("Content-Type", "application/json; charset=UTF-8");
//        Map<String, String> querys = new HashMap<String, String>();
//        querys.put("idcard", "410482200301067719");
//        querys.put("name", "武奕哲");
//        String bodys = "";
//
//
//        try {
//            /**
//             * 重要提示如下:
//             * HttpUtils请从
//             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
//             * 下载
//             *
//             * 相应的依赖请参照
//             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
//             */
//            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
//            System.out.println(response.toString());
//            //获取response的body
//            //System.out.println(EntityUtils.toString(response.getEntity()));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
}
